<include file="public@header" />
<style>
	.controls{ color:#999}
	.minwidth{width:55px !important}
	div[name='d_gaiban'],div[name='d_al']{ width:100%;float:left;}
	.form-horizontal .control-group1{}
	.inputw{width:80px !important;}
	.marleft{margin-left: 90px !important;}
</style>
</head>
<body>
	<php>$type=''</php>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('Rock/product')}">石材产品库</a></li>
			<li><a href="{:url('Rock/producttypeadd')}">新增石材产品</a></li>
			<li class="active"><a href="">编辑生态墓</a></li>
		</ul>
		<form method="post" class="form-horizontal js-ajax-form" action="{:url('Rock/productstedit')}" style="width:100%; float:left">
			<fieldset>
				<div class="p_title">
					<span class="span_title">基础信息</span>
				</div>
				<div class="control-group1-p">
					<div class="form-group"  style="float:left;margin-bottom: -20px;">
						<label class="control-label">状态:</label>
						<div class="col-md-2">
							<select class="form-control" name="if_create" style="width: 136px">
								<if condition="$if_create eq 1">
									<option value="1" selected>启用</option>
									<option value="2">停用</option>
									<else/>
									<option value="1">启用</option>
									<option value="2"selected>停用</option>
								</if>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="control-label">在产状态:</label>
						<div class="col-md-2">
							<select class="form-control" name="if_create" style="width: 136px">
								<if condition="$if_create eq 1">
									<option value="1" selected>在产</option>
									<option value="2">停产</option>
									<else/>
									<option value="1">在产</option>
									<option value="2"selected>停产</option>
								</if>
							</select>
						</div>
					</div>
					<div class="form-group"  >
						<label class="control-label">产品名称:</label>
						<div class="col-md-2" style="width: 12%">
							<input type="hidden" class="form-control" name="mb[id]" required value="{$id}">
							<input type="hidden" class="form-control" name="mb[pro_code]" required value="{$pro_code}">
							<input type="hidden" class="form-control" name="mb[pro_type]" required value="{$pro_type}">
							<input type="text" class="form-control" name="pro_name" required value="{$pro_name}">
						</div>
						<label class="control-label inputw">规制:</label>
						<div class="col-md-2" style="width: 8%">
							<select class="form-control" name="mb[regulation]"style="width: 100px">
								<if condition="$regulation eq 1">
									<option value="1" selected>单穴</option>
									<option value="2">双穴</option>
									<option value="3">三穴</option>
								<elseif condition="$regulation eq 2" />
									<option value="1">单穴</option>
									<option value="2" selected>双穴</option>
									<option value="3">三穴</option>
								<else/>
									<option value="1">单穴</option>
									<option value="2">双穴</option>
									<option value="3" selected>三穴</option>
								</if>
							</select>
						</div>
						<label class="control-label inputw">碑型:</label>
						<div class="col-md-2" style="width: 8%">
							<select class="form-control" name="mb[stele_type]"style="width: 100px">
								<if condition="$stele_type eq 3">
									<option value="3" selected>纪念墙</option>
									<option value="4">卧碑</option>
								<else/>
									<option value="3">纪念墙</option>
									<option value="4" selected>卧碑</option>
								</if>
							</select>
						</div>
						<label class="control-label inputw">占地长度:</label>
						<div class="col-md-2" style="width: 11%">
							<input type="text" class="form-control" style="width: 110px"  name="mb[pro_length]" required value="{$pro_length}"> mm
						</div>
						<label class="control-label inputw" >占地宽度:</label>
						<div class="col-md-2" style="width: 11%">
							<input type="text" class="form-control" style="width: 110px"  name="mb[pro_width]" required value="{$pro_width}"> mm
						</div>
                        <label class="control-label inputw" >价格：</label>
                        <div class="col-md-2" style="width: 8%">
                        <input type="text" class="form-control" style="width: 110px" name="mb[pro_price]" required
                               value="{$pro_price}">
                        </div>
					</div>
					<div class="form-group"  >
						<label class="control-label">产品图</label>
						<div class="col-md-2" style="width: 24.1%">
							<php>$img_url=cmf_get_image_preview_url($pro_photo);</php>
							<input type="hidden" name="mb[pro_photo]" id="thumb" value="{$img_url}">
							<a href="javascript:uploadOneImage('图片上传','#thumb');">
								<h5 class="btn btn-primary">上传</h5>
								<img src="{$img_url}" id="thumb-preview" width="135" style="cursor: hand"/>
							</a>
							<input type="button" class="btn btn-sm" onclick="$('#thumb-preview').attr('src','');$('#thumb').val('');return false;" value="取消图片">
						</div>
					</div>
				</div>
                <div class="p_title">
                	<span class="span_title">墓碑信息</span>
                </div>
                <div class="control-group1-p">
					<div class="form-group">
						<label class="control-label" style="width: 125px;"></label>
						<div class="col-md-2">
							<input type="text" class="form-control minwidth" disabled value="宽">
							<input type="text" class="form-control minwidth" disabled value="高">
							<input type="text" class="form-control minwidth" disabled value="厚">
						</div>
					</div>
					<foreach name="infoData" item="vo" key="d">
						<div  class="form-group part_base" style="margin-bottom: -15px !important;" name="base">
							<div class="control-group1" style="width: 22%">
								<label class="control-label">{$vo.iname}:</label>
								<input type="hidden" name="details[{$d}][id]" value="{$vo.id}" >
								<input type="hidden" name="details[{$d}][iname]" value="{$vo.iname}" >
								<input type="hidden" name="details[{$d}][isort]" value="{$vo.isort}" >
								<div class="controls">
								   <input type="text" class="form-control minwidth iwidth" name="details[{$d}][iwidth]" placeholder="宽"  value="{$vo.iwidth}">
								   <input type="text" class="form-control minwidth iheight" name="details[{$d}][iheight]" placeholder="高"  value="{$vo.iheight}">
								   <input type="text" class="form-control minwidth ithick" name="details[{$d}][ithick]" placeholder="厚"  value="{$vo.ithick}"> mm
								</div>
							</div>
							<div class="control-group1" style="width: 20%">
								<label class="control-label">材料种类:</label>
								<div class="controls">
									<select class="form-control icate" name="details[{$d}][icate]">
										<volist name="cate_type" id="voc">
											<if condition="$vo.icate eq $voc.id">
												<option value="{$voc.id}"  data-stuff_money="{$voc.stuff_money}" selected>{$voc.name}</option>
											<else/>
												<option value="{$voc.id}" data-stuff_money="{$voc.stuff_money}">{$voc.name}</option>
											</if>
										</volist>
									</select>
								</div>
							</div>
							<div class="control-group1" style="width:12%">
								<label class="control-label inputw">数量:</label>
								<div class="controls marleft">
								   <input type="text" class="form-control" name="details[{$d}][inumber]" style="width:100px;" value="{$vo.inumber}">
								</div>
							</div>
							<div class="control-group1" style="width:12%">
								<label class="control-label inputw">材料价格:</label>
								<div class="controls marleft">
									<input type="text" class="form-control imaterial_price" name="details[{$d}][imaterial_price]" style="width:100px;" value="{$vo.imaterial_price}">
								</div>
							</div>
							<div class="control-group1" style="width:12%">
								<label class="control-label inputw">维修单价:</label>
								<div class="controls marleft">
								   <input type="text" class="form-control irepair_price" name="details[{$d}][irepair_price]" style="width:100px;" value="{$vo.irepair_price}">
								</div>
							</div>
							<div class="control-group1"  style="width:12%">
								<label class="control-label inputw">更换单价:</label>
								<div class="controls marleft">
								   <input type="text" class="form-control ichange_price" name="details[{$d}][ichange_price]" style="width:100px;" value="{$vo.ichange_price}">
								</div>
							</div>
						</div>
					</foreach>
                </div>
			</fieldset>
			<div class="form-actions">
				<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
				<a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
			</div>            
		</form>

	</div>
    <script type="text/javascript" src="__STATIC__/js/admin.js?v={:time()}"></script>
	<script type="text/javascript" src="__STATIC__/js/layer/layer.js"></script>
	<script>
		$(document).ready(function(){
			// 主要
			// $(document).on('blur',".imaterial_price",function(){
			// 	var width = $(this).closest("div[name='base']").find(".iwidth").val();
			// 	var height = $(this).closest("div[name='base']").find(".iheight").val();
			// 	var thick = $(this).closest("div[name='base']").find(".ithick").val();
			// 	var material_price = $(this).closest("div[name='base']").find(".imaterial_price").val();
			// 	var change_price = 0;
			// 	if(width != '' && height !='' && thick !='' && material_price != ''){
			// 		change_price = width*height*thick*material_price;
			// 		change_price = change_price.toFixed(2);
			// 	}
			// 	$(this).closest("div[name='base']").find(".ichange_price").val(change_price);
			// });

			$(document).on('blur',".iwidth",function(){
				var obj = $(this).closest('.part_base');
				price_count(obj)
			});
			$(document).on('blur',".iheight",function(){
				var obj = $(this).closest('.part_base');
				price_count(obj)
			});
			$(document).on('blur',".ithick",function(){
				var obj = $(this).closest('.part_base');
				price_count(obj)
			});
			$(document).on('blur',".imaterial_price",function(){
				var obj = $(this).closest('.part_base');
				price_count(obj)
			});
			// 主要
			$(document).on('change',".icate",function(){
				var obj = $(this).closest('.part_base');
				var stuff_money = obj.find('.icate').children('option:selected').data('stuff_money');
				obj.find('.imaterial_price').val(stuff_money)
				price_count(obj)
			});
			var price_count = function(obj){
				var iwidth = obj.find('.iwidth').val()/1000,
						iheight = obj.find('.iheight').val()/1000,
						ithick = obj.find('.ithick').val()/1000,
						imaterial_price =  obj.find('.imaterial_price').val();
				console.log(iwidth)
				console.log(iheight)
				console.log(ithick)
				var change_price = 0;
				if(iwidth != '' && iheight !='' && ithick !=''  && imaterial_price != ''){
					change_price = iwidth*iheight*ithick*imaterial_price;
					change_price = change_price.toFixed(2);
				}
				obj.find(".ichange_price").val(change_price);
			};

		})
	</script>
